--- Inconvenience in the pattern compiler
--- This code shouldn't give a warning
module tests.comp.Issue333 where

data Test = Test { x :: Int }

foo :: Test -> [Int] -> IO ()
foo _ [] = pure ()
foo (t@Test{}) (y:ys) = foo t ys

-- the example is a bit contrieved, however we could cover it
-- by checking the second columns of patterns first:

oof  []    _          = pure ()
oof (y:ys) (t@Test{}) = foo t ys

{- 
    more generally, whenever we see that the first column
    of patterns is not homogenous, we could instead look
    for another column that is homogenous and check that one first.
    That is

    case (a,b) of
       (X,  Con1) ->  ex1
       (v2, Con2) ->  ex2
       (Y,  Con1) ->  ex3
       
    would be transformed to
    
    case (b,a) of
        (Con1, X)  -> ex1
        (Con2, v2) -> ex2
        (Con1, Y)  -> ex3
        
    and the pattern compiler would give us
    
    case b of
        Con1 -> case a of
            X -> ex1
            Y -> ex3
        Con2 -> case a of
            v2 -> ex2  


-}

cons (Just Nothing) _ = 1
cons (Just a)       _ = 2
cons Nothing        _ = 3

--- More general case: patterns are complete, and yet there are two warnings!
general Nothing []    = 42
general _       (_:_) = 43
general (Just _) 
                []   = 44

--- and the reverse case that has no warnings
lareneg [] Nothing = 42
lareneg (_:_) _     = 43
lareneg [] (Just _) = 44

main = println "No warning anymore for foo, lines 7-9"